home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / CmplxSCHUR.cc < prev    next >
C/C++ Source or Header  |  1996-03-03  |  3KB  |  134 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "CmplxSCHUR.h"
  32. #include "f77-fcn.h"
  33. #include "lo-error.h"
  34. #include "mx-inlines.cc"
  35.  
  36. extern "C"
  37. {
  38.   int F77_FCN (zgeesx, ZGEESX) (const char*, const char*,
  39.                 ComplexSCHUR::select_function,
  40.                 const char*, const int&, Complex*,
  41.                 const int&, int&, Complex*, Complex*,
  42.                 const int&, double&, double&,
  43.                 Complex*, const int&, double*, int*,
  44.                 int&, long, long);
  45. }
  46.  
  47. static int
  48. select_ana (const Complex& a)
  49. {
  50.   return a.real () < 0.0;
  51. }
  52.  
  53. static int
  54. select_dig (const Complex& a)
  55. {
  56.   return (abs (a) < 1.0);
  57. }
  58.  
  59. int
  60. ComplexSCHUR::init (const ComplexMatrix& a, const string& ord)
  61. {
  62.   int a_nr = a.rows ();
  63.   int a_nc = a.cols ();
  64.  
  65.   if (a_nr != a_nc)
  66.     {
  67.       (*current_liboctave_error_handler)
  68.     ("ComplexSCHUR requires square matrix");
  69.       return -1;
  70.     }
  71.  
  72.   char jobvs = 'V';
  73.   char sense = 'N';
  74.   char sort = 'N';
  75.  
  76.   char ord_char = ord.empty () ? 'U' : ord[0];
  77.  
  78.   if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd')
  79.     sort = 'S';
  80.  
  81.   if (ord_char == 'A' || ord_char == 'a')
  82.     selector = select_ana;
  83.   else if (ord_char == 'D' || ord_char == 'd')
  84.     selector = select_dig;
  85.   else
  86.     selector = 0;
  87.  
  88.   int n = a_nc;
  89.   int lwork = 8 * n;
  90.   int info;
  91.   int sdim;
  92.   double rconde;
  93.   double rcondv;
  94.  
  95.   schur_mat = a;
  96.   unitary_mat.resize (n, n);
  97.  
  98.   Complex *s = schur_mat.fortran_vec ();
  99.   Complex *q = unitary_mat.fortran_vec ();
  100.  
  101.   Array<double> rwork (n);
  102.   double *prwork = rwork.fortran_vec ();
  103.  
  104.   Array<Complex> w (n);
  105.   Complex *pw = w.fortran_vec ();
  106.  
  107.   Array<Complex> work (lwork);
  108.   Complex *pwork = work.fortran_vec ();
  109.  
  110.   // bwork is not referenced for non-ordered Schur.
  111.  
  112.   Array<int> bwork;
  113.  
  114.   if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd')
  115.     bwork.resize (n);
  116.  
  117.   int *pbwork = bwork.fortran_vec ();
  118.  
  119.   F77_XFCN (zgeesx, ZGEESX, (&jobvs, &sort, selector, &sense, n, s, n,
  120.                  sdim, pw, q, n, rconde, rcondv, pwork,
  121.                  lwork, prwork, pbwork, info, 1L, 1L));
  122.  
  123.   if (f77_exception_encountered)
  124.     (*current_liboctave_error_handler) ("unrecoverable error in zgeesx");
  125.  
  126.   return info;
  127. }
  128.  
  129. /*
  130. ;;; Local Variables: ***
  131. ;;; mode: C++ ***
  132. ;;; End: ***
  133. */
  134.